﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPNETPerformance.App_BusinessLogic.BasePages;

namespace ASPNETPerformance._09_Test {
    public partial class CodeTimer : BasePage {
        protected void Page_Load( object sender, EventArgs e ) {
            if ( !this.Page.IsPostBack ) {
                this.lResult1.Text = ASPNETPerformance.App_BusinessLogic.Utils.CodeProfile.CodeTimer.Time( "Entity Framework", 10,
                                                                                            GetCategoryAllByEdmx );

                this.lResult2.Text = ASPNETPerformance.App_BusinessLogic.Utils.CodeProfile.CodeTimer.Time( "ADO 5大对象", 10,
                                                                                            GetCategoryAllByAdo5Object );

            }
        }

        private void GetCategoryAllByEdmx() {
            var ef = new App_BusinessLogic.Data.NORTHWNDEntities();
            var query = from c in ef.Categories
                        orderby c.CategoryID
                        select c;

            var result = query.ToList();
        }

        private void GetCategoryAllByAdo5Object() {
            SqlConnection conn =
                new SqlConnection( ConfigurationManager.ConnectionStrings[ "NorthwindConnectionString" ].ConnectionString );
            SqlDataAdapter cmd = new SqlDataAdapter( "SELECT * FROM Categories ORDER BY Categories.CategoryID", conn );

            DataTable dt = new DataTable( "CategoryByAll" );
            cmd.Fill( dt );
        }
    }
}